import apiUrl from './apiUrl';
import siteInfo from './../siteInfo';

const spliceUrl = (ip: any, apiUrl: any) => {
    let newUrl:any = {};
    for (let k in apiUrl) {
        let newOb:any = {
            [k]: {}
        };
        for (let i in apiUrl[k]) {
            newOb[k][i] = `${ip}${apiUrl[k][i]}`
        }
        newUrl[k] = newOb[k];
    }
    return newUrl;
};

const appendApiUrl = (siteInfo: any) => {
  if (process.env.NODE_ENV !== 'development') {
    return spliceUrl(siteInfo.apiroot, apiUrl);
  }else{
    return spliceUrl('/myapi/', apiUrl);
  }
};

export default appendApiUrl(siteInfo);
